package org.oslims.server.dao.hbm;

import org.oslims.domain.Mixture;
import org.oslims.domain.MixtureComponent;
import org.oslims.server.dao.MixtureComponentDao;

public class HbmMixtureComponentDao extends HbmGenericDao<MixtureComponent, Long> implements MixtureComponentDao {

	@Override
	public void removeAllComponentsForMixture(Mixture mixture) {

		if (mixture.getComponents().size() > 0) {
			String mixtureIds = "";

			for (MixtureComponent mc : mixture.getComponents()) {
				mixtureIds += mc.getId() + ", ";
			}
			mixtureIds = mixtureIds.substring(0, mixtureIds.length() - 2);

			this.getSession().createQuery("delete MixtureComponent mc where mc.id not in (" + mixtureIds + ") and mc.rootSample.id = :rootSampleId").setLong("rootSampleId",
					mixture.getId()).executeUpdate();
		}
	}

}
